package com.cloud.basic.test;

import cn.hutool.bloomfilter.bitMap.BitMap;
import com.cloud.basic.redis.RedisUtil;
import com.cloud.basic.spring.SpringContextUtils;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.BitSet;
import java.util.concurrent.Future;

@RequestMapping("")
@RestController
public class AsyncTaskController {

    @Autowired
    private AsyncTask asyncTask;

    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("/run")
    public String doTask() throws InterruptedException{
        long currentTimeMillis = System.currentTimeMillis();
        Future<String> task1 = asyncTask.task1();
        Future<String> task2 = asyncTask.task2();
        Future<String> task3 = asyncTask.task3();
        String result = null;
        for (;;) {
            if(task1.isDone() && task2.isDone() && task3.isDone()) {
                // 三个任务都调用完成，退出循环等待
                break;
            }
            Thread.sleep(1000);
        }
        long currentTimeMillis1 = System.currentTimeMillis();
        result = "task任务总耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms";
        return result;
    }


    @PostMapping("/testRedis")
    public void testRedis(){
        String string = redisUtil.hGet("work", "id");
        System.out.println(string);
    }


}
